#ifndef _WX_HYPERLINK_H__
#define _WX_HYPERLINK_H__

#include "wx/defs.h"

#if wxUSE_HYPERLINKCTRL

#include "wx/control.h"

#define wxHL_CONTEXTMENU        0x0001
#define wxHL_ALIGN_LEFT         0x0002
#define wxHL_ALIGN_RIGHT        0x0004
#define wxHL_ALIGN_CENTRE       0x0008
#define wxHL_DEFAULT_STYLE      (wxHL_CONTEXTMENU|wxNO_BORDER|wxHL_ALIGN_CENTRE)

extern const wxChar wxHyperlinkCtrlNameStr[];

class wxHyperlinkCtrl : public wxControl {
  public:
    // Default constructor (for two-step construction).
    wxHyperlinkCtrl() { }

    // Constructor.
    wxHyperlinkCtrl( wxWindow *parent,
                     wxWindowID id,
                     const wxString& label, const wxString& url,
                     const wxPoint& pos = wxDefaultPosition,
                     const wxSize& size = wxDefaultSize,
                     long style = wxHL_DEFAULT_STYLE,
                     const wxString& name = wxHyperlinkCtrlNameStr ) {
      ( void )Create( parent, id, label, url, pos, size, style, name );
    }

    // Creation function (for two-step construction).
    bool Create( wxWindow *parent,
                 wxWindowID id,
                 const wxString& label, const wxString& url,
                 const wxPoint& pos = wxDefaultPosition,
                 const wxSize& size = wxDefaultSize,
                 long style = wxHL_DEFAULT_STYLE,
                 const wxString& name = wxHyperlinkCtrlNameStr );


    // get/set
    wxColour GetHoverColour() const { return m_hoverColour; }
    void SetHoverColour( const wxColour &colour ) { m_hoverColour = colour; }

    wxColour GetNormalColour() const { return m_normalColour; }
    void SetNormalColour( const wxColour &colour );

    wxColour GetVisitedColour() const { return m_visitedColour; }
    void SetVisitedColour( const wxColour &colour );

    wxString GetURL() const { return m_url; }
    void SetURL( const wxString &url ) { m_url = url; }

    void SetVisited( bool visited = true ) { m_visited = visited; }
    bool GetVisited() const { return m_visited; }
  protected:
    // event handlers

    // Renders the hyperlink.
    void OnPaint( wxPaintEvent& event );
    wxRect GetLabelRect() const;
    void OnLeftDown( wxMouseEvent& event );
    void OnLeftUp( wxMouseEvent& event );
    void OnRightUp( wxMouseEvent& event );
    void OnMotion( wxMouseEvent& event );
    void OnLeaveWindow( wxMouseEvent& event );
    void OnPopUpCopy( wxCommandEvent& event );
    void OnSize( wxSizeEvent& event );
    virtual wxSize DoGetBestSize() const;
    virtual void DoContextMenu( const wxPoint & );

  private:
    wxString m_url;
    wxColour m_hoverColour;
    wxColour m_normalColour;
    wxColour m_visitedColour;
    bool m_rollover;
    bool m_visited;
    bool m_clicking;

  private:
    DECLARE_DYNAMIC_CLASS( wxHyperlinkCtrl )
    DECLARE_EVENT_TABLE()
};

BEGIN_DECLARE_EVENT_TYPES()
DECLARE_EXPORTED_EVENT_TYPE(  wxEVT_COMMAND_HYPERLINK, 3700 )
END_DECLARE_EVENT_TYPES()

class wxHyperlinkEvent : public wxCommandEvent {
  public:
    wxHyperlinkEvent() {}
    wxHyperlinkEvent( wxObject *generator, wxWindowID id, const wxString& url )
      : wxCommandEvent( wxEVT_COMMAND_HYPERLINK, id ),
        m_url( url ) {
      SetEventObject( generator );
    }
    wxString GetURL() const { return m_url; }
    void SetURL( const wxString &url ) { m_url = url; }

    // default copy ctor, assignment operator and dtor are ok
    virtual wxEvent *Clone() const { return new wxHyperlinkEvent( *this ); }

  private:

    // URL associated with the hyperlink control that the used clicked on.
    wxString m_url;

    DECLARE_DYNAMIC_CLASS_NO_ASSIGN( wxHyperlinkEvent )
};

typedef void ( wxEvtHandler::*wxHyperlinkEventFunction )( wxHyperlinkEvent& );

#define wxHyperlinkEventHandler(func) \
  (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxHyperlinkEventFunction, &func)

#define EVT_HYPERLINK(id, fn) \
  wx__DECLARE_EVT1(wxEVT_COMMAND_HYPERLINK, id, wxHyperlinkEventHandler(fn))

#ifdef _WX_DEFINE_DATE_EVENTS_
DEFINE_EVENT_TYPE( wxEVT_COMMAND_HYPERLINK )

IMPLEMENT_DYNAMIC_CLASS( wxHyperlinkEvent, wxCommandEvent )
#endif


#endif // wxUSE_HYPERLINKCTRL

#endif // _WX_HYPERLINK_H__
